//------------------------------------------------------------------------------
// Copyright (c) 2008 www.dnaide.com
// Licensed under the MIT (MIT-LICENSE.txt)
//-------------------------------------------------------------------------------------
using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using System.Web;
using DNAide.Core;

namespace DNAide.Web
{
	/// <summary>
	/// Response helper methods
	/// </summary>
	public static partial class ResponseAide
	{

		public static void ForceNoCache()
		{
			ForceNoCache(HttpContext.Current);
		}


		/// <summary>
		/// Force no cache
		/// </summary>
		/// <param name="context"></param>
		public static void ForceNoCache(HttpContext context)
		{
			context.Response.CacheControl = "no-cache";
			context.Response.AddHeader("pragma", "no-cache");
			context.Response.Cache.SetNoStore();
			context.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
			context.Response.Cache.SetLastModified(DateTime.Now);
			context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
			context.Response.Cache.SetExpires(DateTime.Now.AddYears(-1));
		}


		public static void PermanentRedirect(string url)
		{
			PermanentRedirect(HttpContext.Current, url);
		}


		/// <summary>
		/// Redirects to url and adds a status code of 301 "Moved Permanently" to the response header
		/// </summary>
		/// <param name="context"></param>
		/// <param name="url"></param>
		public static void PermanentRedirect(HttpContext context, string url)
		{
			context.Response.ClearContent();
			context.Response.ClearHeaders();

			context.Response.StatusCode = 301;
			context.Response.Status = "301 Moved Permanently";
			context.Response.RedirectLocation = url;
			context.Response.End();
		}

	}
}
